<?php
/**
 *
 */

class DienThoai extends ModelBase
{
    public function __construct()
    {
        parent::__construct(__CLASS__);
    }

    public function getNewPhones()
    {
        $sql = 'SELECT dt.madt as pid, dt.tendt as pname, dt.giadt as pprice, hinhdt as pimgurl ' .
            'FROM dienthoai dt NATURAL JOIN chitietpn ct NATURAL JOIN phieunhap pn ' .
            ' ORDER BY pn.ngaylappn DESC, dt.giadt DESC LIMIT 0 , 10';
        return $this->run($sql);
    }

    public function getHotPhones()
    {
        $sql = 'SELECT dt.madt as pid, dt.tendt as pname, dt.giadt as pprice, hinhdt as pimgurl ' .
                'FROM dienthoai dt NATURAL JOIN chitiethd ct ' .
                'GROUP BY dt.madt ' .
                'ORDER BY COUNT(ct.mahd) DESC LIMIT 0, 10;';
        return $this->run($sql);
    }

    public function del($id)
    {
        $this->delete('madt=:id', array('id' => $id));
        return 1;
    }
}